package com.example.scandemo;

import android.content.Context;

import java.io.File;

import cn.hutool.core.codec.Base64;
import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.crypto.asymmetric.RSA;

public class RSAUtil {
    public static String getRsaStr(String pwds){
        String publicKey =  "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANL378k3RiZHWx5AfJqdH9xRNBmD9wGD2iRe41HdTNF8RUhNnHit5NpMNtGL0NPTSSpPjjI1kJfVorRvaQerUgkCAwEAAQ==";
//        String privateKey = "MIIBUwIBADANBgkqhkiG9w0BAQEFAASCAT0wggE5AgEAAkEA0vfvyTdGJkdbHkB8mp0f3FE0GYP3AYPaJF7jUd1M0XxFSE2ceK3k2kw20YvQ09NJKk+OMjWQl9WitG9pB6tSCQIDAQABAkA2SimBrWC2/wvauBuYqjCFwLvYiRYqZKThUS3MZlebXJiLB+Ue/gUifAAKIg1avttUZsHBHrop4qfJCwAI0+YRAiEA+W3NK/RaXtnRqmoUUkb59zsZUBLpvZgQPfj1MhyHDz0CIQDYhsAhPJ3mgS64NbUZmGWuuNKp5coY2GIj/zYDMJp6vQIgUueLFXv/eZ1ekgz2Oi67MNCk5jeTF2BurZqNLR3MSmUCIFT3Q6uHMtsB9Eha4u7hS31tj1UWE+D+ADzp59MGnoftAiBeHT7gDMuqeJHPL4b+kC+gzV4FGTfhR9q3tTbklZkD2A==";
//        String pwd = "123456";
        RSA rsa = new RSA(null, publicKey);
//        String encrypt = rsa.encryptStr(pwds, KeyType.PublicKey);
//        System.out.println("加密:" + encrypt);
//        String password = new String(rsa.decrypt("MTIzNDU2", KeyType.PrivateKey));
//        System.out.println("解密:" + password);

        byte[] encrypt = rsa.encrypt(pwds.getBytes(), KeyType.PublicKey);
        String outStr = Base64.encode(encrypt);
        System.out.println(outStr);
        return outStr;
    }

    public static String getDecryptStr(String pwd){
        String publicKey =  "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANL378k3RiZHWx5AfJqdH9xRNBmD9wGD2iRe41HdTNF8RUhNnHit5NpMNtGL0NPTSSpPjjI1kJfVorRvaQerUgkCAwEAAQ==";
        RSA rsa = new RSA(null, publicKey);
        String password = new String(rsa.decrypt("MTIzNDU2", KeyType.PrivateKey));
        System.out.println("解密:" + password);
        return password;
    }

    public static String getDir(Context mContext) {
        String path = null;
        File outfile = null;
        String childPath = "/tempFile";
        File yuanti = mContext.getExternalFilesDir("technician");
        outfile = new File(yuanti.getPath(), childPath);
        if (!outfile.isFile()) {
            outfile.mkdirs();
        }
        if (outfile.exists()) {
            path = outfile.getAbsolutePath();
        }
        return path;
    }

    public static String getDir2(Context mContext) {
        String path = null;
        File outfile = null;
        String childPath = "/tempVideo";
        File yuanti = mContext.getExternalFilesDir("technician");
        outfile = new File(yuanti.getPath(), childPath);
        if (!outfile.isFile()) {
            outfile.mkdirs();
        }
        if (outfile.exists()) {
            path = outfile.getAbsolutePath();
        }
        return path;
    }

    public static String getDir3(Context mContext) {
        String path = null;
        File outfile = null;
        String childPath = "/tempVideo";
        File yuanti = mContext.getExternalFilesDir("technician_file");
        outfile = new File(yuanti.getPath(), "");
        if (!outfile.isFile()) {
            outfile.mkdirs();
        }
        if (outfile.exists()) {
            path = outfile.getAbsolutePath();
        }
        return path;
    }
}
